#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

struct stu {
	char number[20];
	int test;
	int truly;
};

//4
//3310120150912233 2 4
//3310120150912119 4 1
//3310120150912126 1 3
//3310120150912002 3 2
//2
//3 4
void f(stu stut[], int test, int n)
{
	int j = 0;
	for (j = 0; j < n; j++)
	{
		if (stut[j].test == test)
		{
			printf("%s %d\n", stut[j].number, stut[j].truly);
		}
	}
}
int main()
{
	int n = 0;
	scanf("%d", &n);
	stu stut[10];
	int i = 0;

	for (i = 0; i < n; i++)
	{
		scanf("%s %d %d", &stut[i].number, &stut[i].test, &stut[i].truly);
	}

	int m = 0;
	scanf("%d", &m);
	int t[100];
	for (i = 0; i < m; i++)
	{
		scanf("%d", &t[i]);
	}

	for (i = 0; i < m; i++)
	{
		f(stut, t[i], n);
	}
	return 0;
}